<cfcomponent extends="Controller">

	<cffunction name="init">
	</cffunction>
	
	<cffunction name="example" returntype="Query" access="private">
		<cfset var players = model("Player").findAll(select="PlayerID,FirstName,LastName") />
		<cfreturn players />
	</cffunction>
	
	<cffunction name="demo">
		<cfset myActionName = "example" />

		<cfset myColumnNames = ArrayNew(1) />
		<cfset myColumnNames[1] = "PlayerID" />
		<cfset myColumnNames[2] = "FirstName" />
		<cfset myColumnNames[3] = "LastName" />
		
		<cfset getdatatablesJS("players",myActionName,"LastName desc, FirstName desc") />
	</cffunction>
	
	<cffunction name="index" hint="List all the players, ability to create new ones">
		<cfset players = model("Player").findAll()>
	</cffunction>
	
	<cffunction name="register">
		<cfset player = model("Player").new()>
	</cffunction>
	
	<cffunction name="display">
		<cfset player = model("Player").findByKey(params.key)>
		<cfif NOT isObject(player)>
			<cfset flashInsert(error="Oops, cannot find that player")>
			<cfset redirectTo(back=true)>
		</cfif>
	</cffunction>
	
	<cffunction name="modify">
		<cfset player = model("Player").findByKey(params.key)>
		<cfif NOT isObject(player)>
			<cfset flashInsert(error="Cannot find that record")>
			<cfset redirectTo(action="index")>
		</cfif>
	</cffunction>
	
	
	<!--- CRUD methods --->
	<cffunction name="create">
		<cfset player = model("Player").create(params.player)>
		<cfif player.hasErrors()>
			<cfset renderPage(action="register")>
		<cfelse>
			<cfset flashInsert(success="Added new player")>
			<cfset redirectTo(action="index")>
		</cfif>
	</cffunction>
	
	<cffunction name="update">
		<cfset player = model("Player").findByKey(params.key)>
		<cfif player.update(params.player)>
			<cfset flashInsert(success="Updated existing player")>
			<cfset redirectTo(action="index")>
		<cfelse>			
			<cfset renderPage(action="modify")>
		</cfif>
	</cffunction>
	
	<cffunction name="delete">
		<cfset player = model("Player").findByKey(params.key)>
		<cfif isObject(player)>
			
		</cfif>
	</cffunction>
	
	<cffunction name="movePosition">
		<cfset player = model("Player").updateByKey(key=params.key,position=params.position)>
		<cfset flashInsert(success="Moved position")>
		<cfset redirectTo(back=true)>		
	</cffunction>
	
</cfcomponent>